
// 统一返回格式
export class ResultModel {
  public code: number;
  public msg?: string;
  public data?: any
}

export const codeList = {
  200: '请求成功',
  204: '没有更多数据',
  404: '资源没找到',
  300: '重定向'
}

const defaultResponse: ResultModel = {
  code: 200,
  msg: codeList[200],
  data: ''
}
export class ResultHelper {
  static response: ResultModel

  static async send(result: ResultModel) {
    let code = result.code
    this.response = {
      code: result.code ? result.code : defaultResponse.code,
      msg: result.msg ? result.msg : codeList[result.code] ? codeList[result.code] : '',
      data: result.data ? result.data : defaultResponse.data
    }
    return this.response
  }
}